using System.Configuration;
using System.Diagnostics;

namespace PostSharp.AspNet
{
    /// <summary>
    /// Configuration section of PostSharp ASP.NET assembly post-processor.
    /// </summary>
    /// <remarks>
    /// This configuration section is optional. By default, the
    /// assembly post-processor expects the variable <code>POSTSHARP20</code>
    /// to be set to the path of the directory containing PostSharp.
    /// </remarks>
    /// <seealso cref="AssemblyPostProcessor"/>
    public sealed class PostSharpConfiguration : ConfigurationSection
    {
        /// <summary>
        /// Gets or sets the list of trace categories.
        /// </summary>
        /// <value>
        /// A comma-separated list of trace categories.
        /// </value>
        [ConfigurationProperty( "trace", DefaultValue = "" )]
        public string TraceCategories
        {
            get { return (string) this["trace"]; }
            set { this["trace"] = value; }
        }

        /// <summary>
        /// Gets or sets the PostSharp project to be executed.
        /// If not specified, the default project is used. 
        /// </summary>
        [ConfigurationProperty( "project" )]
        public string Project
        {
            get { return (string) this["project"]; }
            set { this["project"] = value; }
        }

        /// <summary>
        /// Gets collection of parameters passed to the PostSharp project.
        /// </summary>
        [ConfigurationProperty( "properties", IsDefaultCollection = false )]
        [ConfigurationCollection( typeof(NameValueConfigurationCollection),
            AddItemName = "add",
            ClearItemsName = "clear",
            RemoveItemName = "remove" )]
        public NameValueConfigurationCollection PostSharpProperties
        {
            get { return (NameValueConfigurationCollection) this["properties"]; }
        }

        /// <summary>
        /// Gets collection of parameters passed to the PostSharp project.
        /// </summary>
        [ConfigurationProperty( "searchPath", IsDefaultCollection = false )]
        [ConfigurationCollection( typeof(NameValueConfigurationCollection),
            AddItemName = "add",
            ClearItemsName = "clear",
            RemoveItemName = "remove" )]
        public NameValueConfigurationCollection SearchPath
        {
            get { return (NameValueConfigurationCollection) this["searchPath"]; }
        }


        /// <summary>
        /// If <c>true</c>, the method <see cref="Debugger"/>.<see cref="Debugger.Launch"/>
        /// will be invoked before the execution of PostSharp, given the opportunity to
        /// attach a debugger to the building process.
        /// </summary>
        [ConfigurationProperty( "attachDebugger", DefaultValue = false )]
        public bool AttachDebugger
        {
            get { return (bool) this["attachDebugger"]; }
            set { this["attachDebugger"] = value; }
        }

        /// <summary>
        /// Gets or sets the directory containing PostSharp.
        /// </summary>
        [ConfigurationProperty( "directory")]
        public string Directory
        {
            get { return (string) this["directory"]; }
            set { this["directory"] = value; }
        }

        /// <summary>
        /// Gets or sets the name of the program (for instance, <code>postsharp.2.0-x86.exe</code>)
        /// to be executed.
        /// </summary>
        [ConfigurationProperty("program")]
        public string Program
        {
            get { return (string) this["program"]; }
            set { this["program"] = value; }
        }
    }
}